package cs.xwi7xwa.data;

import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;

public class ExhibitDbAdapter extends DatabaseAdapter
{
    public static final String KEY_ID = "_id";
    public static final String KEY_NAME = "name";
    public static final String KEY_DESC = "description";
    public static final String KEY_IMAGE = "image";
    public static final String DATABASE_TABLE = "exhibit";

    public ExhibitDbAdapter(Context context)
    {
        super(context);
    }

    /**
     * Return a Cursor over the list of all exhibits in the database
     * 
     * @return Cursor over all exhibits
     */
    public Cursor fetchAll()
    {
        return db.query(DATABASE_TABLE, new String[] { KEY_ID, KEY_NAME,
                KEY_DESC, KEY_IMAGE }, null, null, null, null, null);
    }

    /**
     * Return a Cursor positioned at the exhibit that matches the given id
     * 
     * @param id
     *            id of exhibit to retrieve
     * @return Cursor positioned to matching exhibit, if found
     * @throws SQLException
     *             if note could not be found/retrieved
     */
    public Cursor fetch(int id) throws SQLException
    {

        Cursor cursor = db.query(true, DATABASE_TABLE, new String[] { KEY_ID,
                KEY_NAME, KEY_DESC, KEY_IMAGE }, KEY_ID + "=" + id, null, null,
                null, null, null);
        if (cursor != null)
        {
            cursor.moveToFirst();
        }
        return cursor;
    }
}
